<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
</head>
<body>
<script src="/static/nim/js/NIM_Web_SDK_v3.4.0.js"></script>
<script src="/static/nim/js/NIM_Web_NIM_v3.4.0.js"></script>
<!-- 是否使用聊天室 -->
<!-- <script src="path/to/Web_SDK_Chatroom_v.js"></script> -->
<script>
    var data = {};
    var nim = SDK.NIM.getInstance({
        //控制台日志，上线时应该关掉
        debug: true || { api: 'info', style: 'font-size:14px;color:blue;background-color:rgba(0,0,0,0.1)' },
        //应用的appkey
        appKey: '49375d56619322b7f929cc3c13c62195',
        //云信账号
        account: '{$data.accid}',
        //云信token
        token: '{$data.token}',
        //连接
        onconnect: onConnect,
        ondisconnect: onDisconnect,
        onerror: onError.bind(this),
        onwillreconnect: onWillReconnect,
        // 多端登录变化
        onloginportschange:onLoginPortsChange,
        // 群
        onteams: onTeams,
//        onupdateteammember: onUpdateTeamMember,
//        onteammembers: onTeamMembers,
        //消息
        onmsg: onMsg,
//        onroamingmsgs: saveMsgs,
//        onofflinemsgs: saveMsgs,
        //会话
        onsessions: onSessions,
        onupdatesession: onUpdatesession,
        //同步完成
//        onsyncteammembersdone: onSyncTeamMembersDone,
        onsyncdone: onSyncDone,

        //个人信息
        onmyinfo:onMyInfo,
        onupdatemyinfo:onMyInfo,
        //系统通知
        onsysmsg: onSysMsg,
        onofflinesysmsgs: onOfflineSysmsgs,
        onupdatesysmsg:onSysMsg,
        oncustomsysmsg:onCustomSysMsg,
        onofflinecustomsysmsgs:onOfflineCustomSysMsgs,
        // 静音，黑名单，好友
        onmutelist:onMutelist,
        onblacklist: onBlacklist,
        onfriends:onFriends,
        onsynccreateteam:onSyncCreateteam,
        onsyncmarkinblacklist:onSyncMarkinBlacklist,
        onsyncmarkinmutelist:onSyncMarkinMutelist,
        onsyncfriendaction:onSyncFriendAction
    });

    function onConnect() {
        console&&console.log('连接成功');
    };

    function onWillReconnect(obj){
        // 此时说明 `SDK` 已经断开连接，请开发者在界面上提示用户连接已断开，而且正在重新建立连接
    };

    function onError(error) {
        console.log('错误信息' + error);
    };
    function onDisconnect(error) {
        // 此时说明 `SDK` 处于断开状态，开发者此时应该根据错误码提示相应的错误信息，并且跳转到登录页面
        var that = this;
        console.log('连接断开');
        if (error) {
            switch (error.code) {
                    // 账号或者密码错误, 请跳转到登录页面并提示错误
                case 302:
                    alert(error.message);
                    //window.location.href = '{:url("index")}';
                    break;
                    // 被踢, 请提示错误后跳转到登录页面
                case 'kicked':
                    var map={
                        PC:"电脑版",
                        Web:"网页版",
                        Android:"手机版",
                        iOS:"手机版",
                        WindowsPhone:"手机版"
                    };
                    var str =error.from;
                    alert("你的帐号于"+dateFormat(+new Date(),"HH:mm")+"被"+(map[str]||"其他端")+"踢出下线，请确定帐号信息安全!");
                    //跳转至登录页面
                    window.location.href =  '{:url("index")}';
                    break;
                default:
                    break;
            }
        }
    };
    function onLoginPortsChange(loginPorts) {
        console.log('当前登录帐号在其它端的状态发生改变了', loginPorts);
        this.controller.loginPorts(loginPorts);
    };
    function onTeams(teams) {
        console.log('收到群列表', teams);
    };
    function onFriends(friends){
        console.log('收到好友列表', friends);
    };
    function onSessions(sessions){
        console.log('收到会话列表', sessions);
    };
    function onUpdatesession(session){
        console.log('会话更新了', session);
    };
    function onSyncDone() {
        console.log('消息同步完成');
    };
    function onMsg(msg) {
        console.log('收到消息', msg.scene, msg.type, msg);
    };
    function onOfflineSysmsgs(sysMsgs){
        console.log('收到离线消息', obj);
    }
    function onSysMsg(newMsg, msg) {
        console.log('收到系统通知', sysMsg)
    };

    function onCustomSysMsg(msg){
        console.log('收到自定义系统通知', sysMsg);
    };
    function onOfflineCustomSysMsgs(msgs){
        console.log('收到离线自定义系统通知', sysMsgs);
    };
    // 黑名单
    function onBlacklist(blacklist){
        console.log('收到黑名单', blacklist);
    };
    //静音
    function onMutelist(mutelist){
        console.log('收到静音列表', mutelist);
    };

    function onMyInfo(data){
        console.log('收到我的名片', data);
    };

    function onSyncCreateteam(data){
        console.log('同步群列表完成');
    };
    // 多端同步好友关系
    function onSyncFriendAction(data){
        console.log('同步其他端好友申请完成');
    };

    function onSyncMarkinBlacklist(param){
        console.log('同步其他端黑名单完成');
    };

    function onSyncMarkinMutelist(param){
        console.log('同步其他端静音列表完成');
    };
</script>
</body>
</html>